<template>
    <view class="goods-list-item">
      <!-- 左边图片 -->
      <view class="item-image">
        <radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioClickHandler"></radio>
        <image :src="goods.goods_small_logo || defaultPic"></image>
      </view>
      <!-- 右边信息 -->
      <view class="item-info">
        <view class="item-info-title">
          {{goods.goods_name}}
        </view>
        <view class="item-info-bottom">
          <text>
            ¥ {{ goods.goods_price | tofixed}}
          </text>
          <uni-number-box :min="1" v-if="showNum" :value="goods.goods_count" @change="numChangeHandler" @blur="numBlur"></uni-number-box>
        </view>
      </view>
    </view>
</template>

<script>
  export default {
    name:"my-goods",
    data() {
      return {
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    props: {
      goods: {
        type: Object,
        // default: () => {
        //   return {}
        // }
        default: {
        }
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNum: {
        type: Boolean,
        default: false
      }
    },
    filters: {
      tofixed(num){
        return Number(num).toFixed(2)
      }
    },
    methods: {
      radioClickHandler(e){
        this.$emit('radio-change', {
          goods_id: this.goods.goods_id,
          goods_state: !this.goods.goods_state
        })
      },
      numChangeHandler(val){
        console.log('numchange', val)
        
        if(!val){
          this.$emit('num-change', {
            goods_id: this.goods.goods_id,
            goods_count: 1
          })
        }else{
          this.$emit('num-change', {
            goods_id: this.goods.goods_id,
            goods_count: val
          })
        }
      },
      numBlur(e){
        return

      }
      
    }
  }
</script>

<style lang="scss">
    .goods-list-item{
      display: flex;
      border-bottom: 1px solid #F5F5F5;
      padding: 12rpx;
      .item-image{
        display: flex;
        align-items: center;
        image{
          width: 200rpx;
          height: 200rpx;
        }
      }
      .item-info{
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        margin-left: 16rpx;
        .item-info-title {
          font-size: 24rpx;
        }
        
        .item-info-bottom{
          display: flex;
          justify-content: space-between;
          align-items: center;
          text {
            color: #c00000;
            font-size: 28rpx;
            font-weight: bold;
          }
        }
        
        
      }
    }
</style>
